package com.fdb.efp.nls.service.impl.yed.timeTask;

import com.fdb.efp.nls.service.facade.NlsApplyInfoService;
import com.fdb.efp.nls.service.facade.queue.NlsProcessBizService;
import com.fdb.efp.nls.service.facade.yed.YedTaskNlsApplyInfoService;
import com.fdb.efp.nls.service.vo.NlsApplyInfoVO;
import com.fdb.efp.nls.service.vo.queue.NlsProcessBizVO;
import com.fdb.efp.nls.service.impl.yed.apply.YedSyncLoanInfoServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 需求编号：【2019D0509】（业务提的需求编号）
 * 问题编号：【】（若不是因为修复问题而新增该类，则留空）
 * 开发人员：【wanglh4】
 * 创建日期：【2020/3/25 10:54】
 * 功能描述：
 */
@Service("yedTaskNlsApplyInfoService")
public class YedTaskNlsApplyInfoServiceImpl implements YedTaskNlsApplyInfoService {

    private static Logger logger = LoggerFactory.getLogger(YedTaskNlsApplyInfoServiceImpl.class);

    @Autowired
    @Qualifier("nlsApplyInfoService")
    private NlsApplyInfoService nlsApplyInfoService;

    @Autowired
    @Qualifier("nlsProcessBizService")
    private NlsProcessBizService nlsProcessBizService;

    @Autowired
    @Qualifier("yedSyncLoanInfoService")
    private YedSyncLoanInfoServiceImpl yedSyncLoanInfoService;

    @Override
    public void yedSnys() {
        List<NlsApplyInfoVO> nlsApplyInfoVOS = nlsApplyInfoService.queryNlsApplyInfoByDnstsAndState4Yed();
        if (nlsApplyInfoVOS == null || nlsApplyInfoVOS.size() == 0){
            logger.warn(">>>>>>>>查询优e贷放款同步数据为空<<<<<<<<<<");
            return;
        }
        try {
            NlsProcessBizVO nlsProcessBizVO = new NlsProcessBizVO();
            for (NlsApplyInfoVO item : nlsApplyInfoVOS){
                // 根据申请号查询
                nlsProcessBizVO.setApplySeq(item.getApplySeq());
                NlsProcessBizVO queryNlsProcessBizVO = nlsProcessBizService.queryByPk(nlsProcessBizVO);
                yedSyncLoanInfoService.doExecute(queryNlsProcessBizVO,item);
            }
        } catch (Exception e) {
            logger.error(">>>>>>>>>优e贷放款同步任务失败<<<<<<<<<<<" + e);
        } finally {
            logger.info(">>>>>>>>>优e贷放款同步任务结束<<<<<<<<<<<");
        }

    }
}
